package com.fcy.teamwork

import android.app.Application
import android.content.BroadcastReceiver
import android.content.IntentFilter
import cn.jpush.im.android.api.JMessageClient
import com.fcy.teamwork.base.log
import com.fcy.teamwork.pojo.Person
import com.fcy.teamwork.security.NetChangeReceiver
import com.fcy.teamwork.security.environment.EnvironmentSec
import kotlin.system.exitProcess

class App : Application() {

    companion object {
        const val APP_KEY = "b2f74964996ed191437d7fed"
        lateinit var application: Application
        lateinit var person: Person
    }

    override fun onCreate() {
        super.onCreate()
        application = this
        Thread.currentThread().setUncaughtExceptionHandler { t, e ->
            log("发生未捕获的异常 $e")
            e.printStackTrace()
        }
        JMessageClient.init(this)
        // 通知栏
        JMessageClient.setNotificationFlag(JMessageClient.FLAG_NOTIFY_DISABLE)
        if (!EnvironmentSec.isEnvSec(this)) {
            throw IllegalStateException("安全校验不通过")
        }
        initNetListener()
    }

    private fun initNetListener() {
        val filter = IntentFilter().apply {
            addAction("android.net.conn.CONNECTIVITY_CHANGE")
        }
        registerReceiver(NetChangeReceiver(), filter)
    }
}